package main

import (
	"fmt"
	"math"
)

func main() {
	prices := []int{7,6,4,3,1}
	p := maxProfit(prices)
	fmt.Println(p)
}

func maxProfit(prices []int) int {
	minProfit := 0
	minPrice := math.MaxInt
	for i := 0; i < len(prices); i++ {
		if prices[i] < minPrice {
			minPrice = prices[i]
		} else if prices[i]-minPrice > minProfit {
			minProfit = prices[i] - minPrice
		}
	}

	return minProfit
}
